package edu.upc.dew.dao;

import edu.upc.dew.entity.Category;
import java.util.List;
import javax.sql.DataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.stereotype.Repository;

/**
 *
 * @author gian.corzo
 */
@Repository
public class CategoryDao extends JdbcDaoSupport {

    private static final Logger log = LoggerFactory.getLogger(CategoryDao.class);

    @Autowired
    public CategoryDao(DataSource dataSource) {
        setDataSource(dataSource);
    }

    public List<Category> getCategories() {
        return getJdbcTemplate().query(
                "select * from categories",
                new BeanPropertyRowMapper<Category>(Category.class));
    }

}
